For information about scripting the <A>
element, see the Scripting the <A> element topic.
The Anchor element is the essence of HTML. It is marked text that is the start and/or destination of a hypertext link. Anchor elements are defined by the <A>
element. The <A>
element accepts several attributes, but either the NAME or HREF attribute is required.
Attributes of the <A>
element :
HREF
If the HREF
attribute is present, the text between the opening and closing anchor elements becomes a hypertext link. If the link is selected by readers, they are moved to the document or location specified by the value of the attribute.
Example :
See <A HREF="http://subnet.virtual-pc.com/~le387818/">The HTMLib site</A> for updated info on the HTMLib.
In this example, selecting "The HTMLib" takes the reader to a document located at http://subnet.virtual-pc.com/~le387818/ (which is the HTMLib web site)
With the HREF
attribute, the form HREF="#identifier"
can refer to another anchor in the same document.
Example :
The <A HREF="document.html#glossary">glossary</A> defines terms used in the document.
In this example, selecting "glossary" takes the reader to another anchor (i.e. <A NAME="glossary">Glossary</A>
) in the document document.html. The NAME
attribute is described below. If the anchor is in another document and the HREF
attribute provides a partial URL, the new document will be resolved from either the present document, or from any specified base address.
Several other forms of the HREF
attribute are permitted by browsers. They are as follows :
<A HREF="http://...">
<A HREF="ftp://...">
<A HREF="gopher://...">
<A HREF="mailto:...">
<A HREF="mailto:cmlehunt@swan.ac.uk?subject=The HTMLib is fantastic">link text</A>
. Note that for Internet Explorer the above syntax example will only work with certain mail applications. Notably, the Internet mail add-on for Internet Explorer doesn't support this method.
<A HREF="news:...">
<A HREF="newsrc:...">
<A HREF="nntp://...">
<A HREF="telnet://...">
<A HREF="wais://...">
<A HREF="view-source:...">
HREF
attribute value forces the Netscape 'View Source' function, opening up the standard source viewing window with the document specified in the value. The URL to the document must be fully qualified. Also note that this is an undocumented feature, whose support may possibly change without notice.
NAME
If present, the NAME
attribute allows the anchor to be the target of a link. The value of the NAME
attribute is an identifier for the anchor. Identifiers are arbitrary strings but must be unique within the HTML document. Also, note that they are case sensitive within HTML documents and can not contain spaces.
Example of use:
<A NAME="coffee">Coffee</A> is an example of...
An example of this is <A HREF="#coffee">coffee</A>.
Another document can then make a reference explicitly to this anchor by putting the identifier after the address, separated by a hash character :
<A HREF="drinks.html#coffee">
TITLE
The TITLE
attribute is for informational purposes only (unless used with a mailto: attribute). If present, the Title attribute should provide the title of the document whose address is given by the HREF
attribute. When it was introduced, it was anticipated that perhaps browsers would display the contents of the TITLE
attribute when the user focuses on the link (like a ToolTip), however, browser vendors haven't yet implemented this.
REL
The REL
attribute gives the relationship(s) described by the hypertext link from the anchor to the target. The value should be a comma-separated list of relationship values. Values and their semantics will be registered by the HTML registration authority. The default relationship if none other is given is void. The REL
attribute is only used when the HREF
attribute is present. (See also <LINK REL="...">
)
REV
The REV
attribute is the same as the REL
attribute, but the semantics of the link type are in the reverse direction. A link from A to B with REL
="X" expresses the same relationship as a link from B to A with REV
="X". An anchor may have both REL
and REV
attributes. (See also <LINK REV="...">
)
URN
If present, the URN
attribute specifies a uniform resource name (URN
) for a target document. The format of URN
s is still under discussion (since 1994) by various working groups of the Internet Engineering Task Force.
METHODS
The METHODS
attributes of anchors and links provide information about the functions that the user may perform on an object. These are more accurately given by the HTTP protocol when it is used, but it may, for similar reasons as for the TITLE
attribute, be useful to include the information in advance in the link. For example, the HTML user agent may chose a different rendering as a function of the methods allowed; for example, something that is searchable may get a different link appearance.
The value of the METHODS
attribute should be a comma separated list of HTTP methods supported by the object for public use.
TARGET
Browser windows can now have names associated with them. Links in any window can refer to another window by name. When the link is activated, the document referenced will appear in that named window. If the window is not already open, the browser will open and name a new window for you. Such an action is only supported by frames capable browsers (i.e. Netscape and Internet Explorer.)
The syntax for the targeted windows is:
<A HREF="url.html" TARGET="window_name">Link text</A>
The TARGET
attribute can accept the following values :
<FRAME>
element, or by using the window.open
scripting method. If a window_name
is used which does not correlate to a previously defined window, then a new window is created and NAME
d according the the window name used in the TARGET
attribute. This new window can then be referenced using it's new name.
<FRAMESET>
element definitions that control the form's current window.
TARGET="window_name"
where the window_name used is not a previously defined window. NOTE : Unlike using the window_name
using a previously undefined window name, using _blank
will not name the new window for future use.
See Also, <BASE TARGET=...>
<A>
can also take the CLASS, ID and STYLE attributes to allow style sheet definitions to be applied to it. For more details of these attributes, see the Style Sheets topic.
The <A>
element style can also be controlled by using the Anchor pseudo-elements.
Using a Style Sheet definition in the <STYLE>
element, the pseudo-classes A:link
, A:visited
and A:active
can be used to set the text style of links, visited links and active links respectively (just as the LINK
, ALINK
and VLINK
attributes of the <BODY>
element do for those browsers that do not support style sheets)